package com.leon.alishop.spider.util;

import org.htmlparser.NodeFilter;
import org.htmlparser.filters.AndFilter;
import org.htmlparser.filters.HasAttributeFilter;
import org.htmlparser.filters.HasParentFilter;
import org.htmlparser.filters.TagNameFilter;

import com.leon.alishop.core.enumeration.TaobaoStoreTypeEnum;

public class AlibabaNodeFilterUtil {

	/**
	 * 下一页过滤
	 * @return
	 */
	public static  NodeFilter getNextPageFilter(TaobaoStoreTypeEnum type){
		AndFilter retFilter = new AndFilter();
		AndFilter parentFilter = new AndFilter();
		parentFilter.setPredicates(new NodeFilter[]{
				new TagNameFilter("li"),
				new HasAttributeFilter("class", "pagination")
		});
		retFilter.setPredicates(new NodeFilter[]{
				new TagNameFilter("a"),
				new HasAttributeFilter("class", "next")
		});
		return retFilter;
	}
	
	/**
	 * 列表商品过滤
	 * @return
	 */
	public static NodeFilter getItemFilter(){
		AndFilter retFilter = new AndFilter();
		AndFilter parentFilter = new AndFilter();
		AndFilter parentFilter1 = new AndFilter();
		parentFilter1.setPredicates(new NodeFilter[]{
				new TagNameFilter("ul"),
				new HasAttributeFilter("class", "offer-list-row")
		});
		parentFilter.setPredicates(new NodeFilter[]{
				new TagNameFilter("div"),
				new HasAttributeFilter("class", "title"),
				new HasParentFilter(parentFilter1,true)
		});
		retFilter.setPredicates(new NodeFilter[]{
				new TagNameFilter("a"),
//				new HasAttributeFilter("class", "permalink"),
				new HasParentFilter(parentFilter)
		});
		return retFilter;
	}
	
}
